package com.hitsoysauce.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hitsoysauce.bean.User;


public class ShowIteratorServlet extends HttpServlet {

	private static final long serialVersionUID = -2922143739743886129L;
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		
		List<User> userList = new ArrayList<User>();
		User user = new User();
		user.setUsername("user1");
		user.setPassword("pass1");
		userList.add(user);
		
		user = new User();
		user.setUsername("user2");
		user.setPassword("pass2");
		userList.add(user);
		
		user = new User();
		user.setUsername("user3");
		user.setPassword("pass3");
		userList.add(user);
		
		user = new User();
		user.setUsername("user4");
		user.setPassword("pass4");
		userList.add(user);
		
		user = new User();
		user.setUsername("user5");
		user.setPassword("pass5");
		userList.add(user);
		
		request.setAttribute("userList", userList);
		request.setAttribute("startDate", new Date());
		
		request.getRequestDispatcher("/showIteratorResult.jsp").forward(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

	@Override
	public void destroy() {
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		super.init();
		
	}

	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
	}

}
